package com.wangxiaoxuan.seckill.controller;


import com.wangxiaoxuan.seckill.service.IUserService;
import com.wangxiaoxuan.seckill.vo.LoginVo;
import com.wangxiaoxuan.seckill.vo.RespBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * @author 王小轩
 * @version 1.0
 */
//@RestController会给所有方法加上    @ResponseBody返回对象
@Controller
@RequestMapping("/login")
@Slf4j
public class LoginController {
    @Autowired
    private IUserService userService;
    /**
     * 跳转登录页面
     * @return
     */
    @RequestMapping("/toLogin")
    public String toLogin(){
        return "login";
    }

    /**
     * 登录
     * @param
     * @return
     */

    @RequestMapping("/doLogin")
    @ResponseBody
    public RespBean doLogin(LoginVo loginVo, HttpServletRequest request, HttpServletResponse response){
       // log.info("{}",loginVo);//这个实在后端控制太打印登录页面传过来的数据，可以注释掉
        userService.doLogin(loginVo,request,response);//调用service层的方法，此处如果抛出异常会被拦截至相应处理类
        return new RespBean().success();
    }
}
